import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { PartialConsult, ConsultIllness, MedicineIllness } from '@/types/consult'
import { ConsultType } from '@/enum'
import type { Medical } from '@/types/room'

export const useConsultStore = defineStore(
  'consult',
  () => {
    //问诊总信息
    const consult = ref<PartialConsult>({})

    //问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)

    //问诊记录级别 /** 快速问诊类型，0 普通 1 三甲 */
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)

    //记录科室 /** 科室ID */
    const setDep = (dep: string) => (consult.value.depId = dep)

    // 记录病情
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    //记录患者
    const setPatient = (patientId: string | undefined) => (consult.value.patientId = patientId)

    //记录优惠券
    const setCoupon = (couponId: string) => (consult.value.couponId = couponId)

    //清理数据
    const clear = () => {
      consult.value = {}
    }

    // 记录问药门诊病情
    const setMedicineIlness = (illness: MedicineIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.liverFunction = illness.liverFunction
      consult.value.renalFunction = illness.renalFunction
      consult.value.allergicHistory = illness.allergicHistory
      consult.value.fertilityStatus = illness.fertilityStatus
      consult.value.pictures = illness.pictures
    }
    /**
     * 添加药品
     */
    const setMedicines = (val: Medical[]) => (consult.value.medicines = val)
    /**
     * 存医生Id字段
     */
    const setDocId = (val: string) => (consult.value.docId = val)
    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear,
      setMedicineIlness,
      setMedicines,
      setDocId
    }
  },
  {
    persist: true
  }
)
